from tortoise import fields
from tortoise.models import Model


class Province(Model):
    id = fields.CharField(pk=True, max_length=20)
    name_cn = fields.CharField(max_length=50)

    class Meta:
        table = "province"


class City(Model):
    id = fields.CharField(pk=True, max_length=20)
    name_cn = fields.CharField(max_length=50)
    province = fields.ForeignKeyField("models.Province", related_name="cities", null=True)
    longitude = fields.DecimalField(max_digits=10, decimal_places=6, null=True)
    latitude = fields.DecimalField(max_digits=10, decimal_places=6, null=True)

    class Meta:
        table = "city"


class District(Model):
    id = fields.CharField(pk=True, max_length=20)
    name_cn = fields.CharField(max_length=50)
    city = fields.ForeignKeyField("models.City", related_name="districts", null=True)

    class Meta:
        table = "district"
